<#--
List of variables to be passed for this template:
        +- rootPackage
        +- applicationName
        +- classNames
        +- directory
        +- Entities: ArrayList of EntityClass.getAsMap()

            |
            +- imports: imports
            |
            +- name: The name of the class.
            |    |
            |    +- single
            |    +- plural
            |
            +- idColumn: the id column
            |    |
            |    +- field
            |    |    |
            |    |    +- name
            |    |    +- type
            |    |
            |    +- getter
            |    +- setter
            |
            +- columns: ArrayList of columns
            |    |
            |    +- field
            |    +- getter
            |    +- setter

-->

<@pp.dropOutputFile />
<#list classNames as className>
<@pp.changeOutputFile name="/development/${directory}/apis/rest/converters/${className.plural}Converter.java" />

package ${rootPackage}.${applicationName}.apis.rest.converters;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import ${rootPackage}.${applicationName}.models.${className.single};

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("${className.plural?uncap_first}")
public class ${className.plural}Converter {

	@XStreamAlias("${className.plural?uncap_first}")
	private Collection<${className.single}Converter> items;

	public ${className.plural}Converter() {
	}

	public ${className.plural}Converter(List<${className.single}> entities) {
		items = new ArrayList<${className.single}Converter>();
		if (entities != null) {
			items.clear();
			for (${className.single} entity : entities) {
				items.add(new ${className.single}Converter(entity));
			}
		}
	}

    public Collection<${className.single}> getEntities()
    {
        Collection<${className.single}> entities = new ArrayList<${className.single}>();
        if (items != null)
        {
            for (${className.single}Converter item : items)
            {
                entities.add(item.getEntity());
            }
        }
        return entities;
    }
}
</#list>
